#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
using namespace std;

class Solution {
public:
    int minNumberOfFrogs(string croakOfFrogs) {
        string str = "croak";
        int n = str.size();
        vector<int> hash(n);
        unordered_map<char, int> index;
        for (int i = 0; i < n; i++)
        {
            index[str[i]] = i;
        }
        for (auto e : croakOfFrogs)
        {
            if (e == 'c')
            {
                if (hash[index[str[n - 1]]] == 0) hash[index[e]]++;
                else
                {
                    hash[index[str[n - 1]]]--;
                    hash[index[e]]++;
                }
            }
            else
            {
                if (hash[index[e] - 1] == 0) return -1;
                else
                {
                    hash[index[e] - 1]--;
                    hash[index[e]]++;
                }
            }
        }
        for (int i = 0; i < n - 1; i++)
        {
            if (hash[i] > 0) return -1;
        }
        return hash[n - 1];
    }
};

int main()
{
    Solution s;
    string croakOfFrogs = "croakcroak";
    int ret = s.minNumberOfFrogs(croakOfFrogs);
    cout << ret;
    return 0;
}